package org.ffmmx.common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class CaptchaUtils {
    @Autowired
    private CacheManager cacheManager;

    public Boolean checkCaptchaCode(String captchaKey,String captchaCode) {
        assert !StringUtils.isEmpty(captchaKey);
        assert !StringUtils.isEmpty(captchaCode);

        final String code = cacheManager.getCache("captcha").get(captchaKey, String.class);
        if(captchaCode.equals(code))
            return true;
        else
            return false;
    }
}
